package com.hw.paltfrom.service.doncutor;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.hw.paltfrom.exception.HWSystemException;
import com.hw.paltfrom.mapper.*;
import com.hw.paltfrom.pojo.*;
import com.hw.paltfrom.rescode.HWSystemCode;
import com.hw.paltfrom.utils.PageUtils;
import com.hw.paltfrom.utils.RandomNumberUtil;
import com.hw.paltfrom.utils.ResponeResultUtil;
import com.hw.paltfrom.vo.FileInfo;
import com.hw.paltfrom.vo.StandCommandTaskVo;
import com.hw.paltfrom.vo.StepInfoVO;
import com.hw.paltfrom.vo.SupervisionVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.sql.Timestamp;
import java.util.*;

/**
 * 站的指挥调度查询 崔孟超 2019年11月7日11:33:53
 */
@Service
public class StationCommandTaskServer {

	@Autowired // 指挥调度任务表
	private HwCommandTaskMapper hwCommandTaskMapper;
	// 超重车辆表的接口
	@Autowired
	private HwDataOverrunstationOverweightMapper dataOverrunstationOverweightMapper;
	// 附件表接口
	@Autowired
	private HwBaseAnnexesfileMapper hwBaseAnnexesfileMapper;
	// 称重督导表
	@Autowired
	private HwSupervisionMapper hwSupervisionMapper;
	// 指挥调度反馈表 HW_Command_TaskFeedback
	@Autowired
	private HwCommandTaskfeedbackMapper hwCommandTaskfeedbackMapper;
	// ：HW_Case_Main 案件表
	@Autowired
	private HwCaseMainMapper hwCaseMainMapper;
	// HW_Case_SrcCom 源头倒查表
	@Autowired
	private HwCaseSrccomMapper hwCaseSrccomMapper;
	// @Autowired HW_Case_PoliceOper 案件交警执法
	@Autowired
	private HwCasePoliceoperMapper hwCasePoliceoperMapper;
	// @Autowired HW_Case_PoliceOper 案件交警执法
	@Autowired //// 创建基础工作流的接口
	private BaseWorkflowService baseWorkflowService;
	// // 向各阶段审批操作过程表插入数据 接口
	@Autowired
	private CommandWorkflowService commandWorkflowService;
    @Autowired //HwDataOverrunstationOverweightMapper
	private  HwDataOverrunstationHistoryMapper hwDataOverrunstationHistoryMapper;
	/**
	 * 站的指挥调度查询
	 *
	 * @param vo
	 * @return
	 */
	public Map<String, Object> query(StandCommandTaskVo vo) {
		// 分页
		Integer pageNum = vo.getPageNum();
		Integer pageSize = vo.getPageSize();

		// 筛选条件
		String cph = vo.getCph();
		// 任务类型（异地复检01；闯卡移交02；逃逸移交03；举报投诉04；其他05）
		String taskType = vo.getTaskType();
		// 完结、 执行中
		String flowStage = vo.getFlowStage();

		// 当前登陆站用户的超限站编号
		String overrunCode = vo.getFoverrunCode();

		EntityWrapper<HwDataOverrunstationOverweight> weightWrapper = new EntityWrapper<HwDataOverrunstationOverweight>();
		if (StringUtils.isNotBlank(cph)) {
			weightWrapper.like("CPH", cph);
		}

		if (StringUtils.isNotBlank(overrunCode)) {
			weightWrapper.eq("F_OverrunCode", overrunCode);
		}

		// Integer selectCount =
		// dataOverrunstationOverweightMapper.selectCount(weightWrapper);
		// 分页

		PageUtils<StandCommandTaskVo> pageUtils = new PageUtils<StandCommandTaskVo>(pageNum, pageSize);
		// PageHelper.startPage(pageNum, pageSize);
		// 筛选后的称重表
		List<HwDataOverrunstationOverweight> overList = dataOverrunstationOverweightMapper.selectList(weightWrapper);

		// 返回数据集合
		ArrayList<StandCommandTaskVo> resultList = new ArrayList<StandCommandTaskVo>();
		for (HwDataOverrunstationOverweight orow : overList) {

			int flag = 0;
			StandCommandTaskVo resultVo = new StandCommandTaskVo();

			// 查询当前称重数据 是否有对应的调度数据
			EntityWrapper<HwCommandTask> taskWrapper = new EntityWrapper<HwCommandTask>();

			if (StringUtils.isNotBlank(taskType)) {
				taskWrapper.eq("Task_Type", taskType);
			}
			// if (StringUtils.isBlank(flowStage)) {
			// taskWrapper.ne("Flow_Stage", "08");
			// }
			if (StringUtils.isNotBlank(flowStage)) {
				taskWrapper.eq("Flow_Stage", flowStage);
			} else {
				taskWrapper.ne("Flow_Stage", "08");
			}
			// HwCommandTask hwCommandTask =new HwCommandTask();
			// hwCommandTask.setfId(orow.getfId());
			// HwCommandTask oldCommandTask =
			// hwCommandTaskMapper.selectOne(hwCommandTask);
			taskWrapper.eq("F_Id", orow.getfId());
			List<HwCommandTask> CommandTaskList = hwCommandTaskMapper.selectList(taskWrapper);
			HwCommandTask entity = new HwCommandTask();
			entity.setfId(orow.getfId());
			HwCommandTask selectOne = hwCommandTaskMapper.selectOne(entity);
			if (!"08".equals(flowStage) && (selectOne != null && selectOne.getFlowStage().equals("08"))) {
				flag = 1;
			}

			HwCommandTask oldCommandTask = null;
			if (!CommandTaskList.isEmpty()) {
				oldCommandTask = CommandTaskList.get(0);
			}
			Integer isSeized = orow.getIsSeized();
			// 按钮显示
			// 调度表没数据，且isSeized==0未查扣
			if (oldCommandTask == null && isSeized == 0) {
				// 满足异地复检、查扣、闯卡移交、逃逸移交 按钮条件
				// EntityWrapper<HwCaseMain> caseMainWrapper = new
				// EntityWrapper<HwCaseMain>();
				// caseMainWrapper.eq("F_Id",
				// orow.getfId()).eq("F_OverrunCode",overrunCode);
				// List<HwCaseMain> hwCaseMains =
				// hwCaseMainMapper.selectList(caseMainWrapper);
				if (orow.getjZz() != null && orow.getjSfcz() == 1) {
					resultVo.setCk(1);
					resultVo.setTyyj(1);

				}
				if (orow.getjZz() == null) {
					resultVo.setyDfj(1);
					resultVo.setCkyj(1);
				}
			}
			if (oldCommandTask != null) {
				String oldflowStage = oldCommandTask.getFlowStage();
				String oldtaskType = oldCommandTask.getTaskType();
				// 情况说明按钮 Flow_Stage=03 and(Task_Type='02' or Task_Type='03')
				if (oldflowStage.equals("03") && (oldtaskType.equals("02") || oldtaskType.equals("03"))) {
					resultVo.setQksm(1);
				}

				// 上报视频
				if ((oldflowStage.equals("03") || oldflowStage.equals("05") || oldflowStage.equals("06")
						|| oldflowStage.equals("07")) && (oldtaskType.equals("02") || oldtaskType.equals("03"))) {
					resultVo.setSpsp(1);
				}

				// 上报移交单
				if (oldflowStage.equals("06") && (oldtaskType.equals("02") || oldtaskType.equals("03"))) {
					resultVo.setSbyd(1);
				}

				// 确认移交
				if (oldflowStage.equals("07") && (oldtaskType.equals("02") || oldtaskType.equals("03"))) {
					resultVo.setQryj(1);
				}
			}
			resultVo.setFoverrunCode(orow.getfOverruncode());
			resultVo.setfId(orow.getfId());
			resultVo.setCph(orow.getCph());
			resultVo.setdZs(orow.getdZs());
			resultVo.setdZz(orow.getdZz());
			resultVo.setdCxl(orow.getdCxl());
			resultVo.setdJcsj(orow.getdJcsj());
			resultVo.setjZz(orow.getjZz());
			resultVo.setjCxds(orow.getjCxds());
			resultVo.setjJcsj(orow.getjJcsj());

			if (oldCommandTask != null) {
				resultVo.setTaskType(oldCommandTask.getTaskType());
				resultVo.setFlowStage(oldCommandTask.getFlowStage());
				resultVo.setTaskId(oldCommandTask.getTaskId());
				resultVo.setFlowCode(oldCommandTask.getFlowCode());
			}

			// 20191124新增规则
			// 如果未分类(调度没数据)
			if (flag == 0 && oldCommandTask == null) {
				
//				未查扣
				if (isSeized == 0) {
					
					if (!(flowStage != null && flowStage.equals("08") && oldCommandTask == null)) {
						if (flag == 0) {
							if (StringUtils.isNotBlank(taskType)) {
								if (oldCommandTask != null) {
									resultList.add(resultVo);
								}
							} else {
								resultList.add(resultVo);
							}
						}
					}
					
					
				}

			} else {

				if (!(flowStage != null && flowStage.equals("08") && oldCommandTask == null)) {
					if (flag == 0) {
						if (StringUtils.isNotBlank(taskType)) {
							if (oldCommandTask != null) {
								resultList.add(resultVo);
							}
						} else {
							resultList.add(resultVo);
						}
					}
				}

			}

		}
		Object info = pageUtils.getPageResult(resultList);
		// PageInfo<StandCommandTaskVo> info = new
		// PageInfo<StandCommandTaskVo>(resultList);
		// info.setTotal(selectCount);
		// info.setPageSize(pageSize);
		return ResponeResultUtil.successNotice(HWSystemCode.SUCCESS, info);

	}


	/**
	 * 站的指挥调度--异地复检
	 *
	 * @param vo
	 * @return
	 */
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { Exception.class, RuntimeException.class,
			HWSystemException.class })
	public Map<String, Object> standRemote(StandCommandTaskVo vo) {
		//超重车辆表 的 GUID
		String fId = vo.getfId();
		HwCommandTask entity = new HwCommandTask();
		entity.setfId(fId);
		HwCommandTask hwCommandTask = hwCommandTaskMapper.selectOne(entity);
		// 查调度表
		HwDataOverrunstationOverweight hwDataOverrunstationOverweight = new HwDataOverrunstationOverweight();
		hwDataOverrunstationOverweight.setfId(fId);
		HwDataOverrunstationOverweight Overweight = dataOverrunstationOverweightMapper
				.selectOne(hwDataOverrunstationOverweight);
		// 按钮提交后需再次验证上述条件是否成立（成立执行，不成立，返回提示“该车辆信息不能进行异地复检处理！”；
		if (!(hwCommandTask == null && Overweight.getIsSeized() == 0)) {
			return ResponeResultUtil.fail(HWSystemCode.OFFSITECODE_EXIT);
		}
		entity.setTaskId(RandomNumberUtil.getNumber());
		entity.setTaskClass(1);
		entity.setTaskType("01");
		entity.setTaskContent(vo.getTaskContent());
		entity.setfFromdeptype(3);
		entity.setfFromdepcode(vo.getfFromdepcode());
		entity.setfFromdepname(vo.getfFromdepname());
		entity.setfAreacode(vo.getfAreacode());
		entity.setfAccount(vo.getfAccount());
		entity.setfCreatetime(new Timestamp(System.currentTimeMillis()));
		entity.setFlowCode("YDFJ");
		// OverrunStation_ID
		HwBaseWorkflow startBaseWorkflow = baseWorkflowService.getStartBaseWorkflow("YDFJ");
		entity.setFlowStage(startBaseWorkflow.getWorkflowNextcode());//workflowCode
		entity.setAssignState(0);
		entity.setIsStagestate(0);
		Integer insert = hwCommandTaskMapper.insert(entity);
		if (insert != 1) {
			return ResponeResultUtil.fail(HWSystemCode.FAIL);
		}
		HwCommandTask commandTask=new HwCommandTask();
		commandTask.setfId(fId);
		HwCommandTask CommandTask = hwCommandTaskMapper.selectOne(commandTask);
//		// HwCommandTask CommandTask = hwCommandTaskMapper.selectOne(entity);
//		// 办理阶段
//		String flowStage = "01";
//		// 流程类型编号
//		String flowCode = entity.getFlowCode();
////		HwBaseWorkflow presentWorkflow = baseWorkflowService.getPresentWorkflow(flowStage, flowCode);
		// 创建各阶段审批操作过程
		HwCommandWorkflow hwCommandWorkflow = new HwCommandWorkflow();
		hwCommandWorkflow.setCommandworkflowId(RandomNumberUtil.getNumber());
		hwCommandWorkflow.setWorkflowModule(startBaseWorkflow.getWorkflowModule());
		hwCommandWorkflow.setWorkflowType(startBaseWorkflow.getWorkflowType());  //workflowType
		hwCommandWorkflow.setWorkflowCode(startBaseWorkflow.getWorkflowCode());
		hwCommandWorkflow.setWorkflowCodename(startBaseWorkflow.getWorkflowCodename());
		hwCommandWorkflow.setCommandworkflowButtonname(vo.getButtonName());
		hwCommandWorkflow.setfAccount(vo.getfAccount());
		hwCommandWorkflow.setfFromdepcode(vo.getfFromdepcode());
		hwCommandWorkflow.setfFromdepname(vo.getfFromdepname());
		hwCommandWorkflow.setCommandworkflowDatatime(new Date());
//		hwCommandWorkflow.setCommandworkflowContent(vo.getTaskContent());
		hwCommandWorkflow.setObjectId(CommandTask.getTaskId());//有什么用字段
		hwCommandWorkflow.setWorkflowNextcode(startBaseWorkflow.getWorkflowNextcode());
		hwCommandWorkflow.setWorkflowNextcodename(startBaseWorkflow.getWorkflowNextcodename());
		// (4.2)各审批操作过程表，插入内容：全部，对应异地复检处理
		// 向各阶段审批操作过程表插入数据
		boolean success = commandWorkflowService.addWorkflow(hwCommandWorkflow);
		if (success == false) {
			// 事务回滚
			throw new HWSystemException();
		}
		return ResponeResultUtil.success(HWSystemCode.SUCCESS);
	}

	/**
	 * 站的指挥调度-查扣
	 *
	 * @param vo
	 * @return
	 */
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { Exception.class, RuntimeException.class,
			HWSystemException.class })
	public Map<String, Object> standDetain(StandCommandTaskVo vo) {
		// 超重车辆表 的 GUID
		String fId = vo.getfId();
		String taskId = vo.getTaskId();
		HwDataOverrunstationOverweight entity = new HwDataOverrunstationOverweight();
		entity.setfId(fId);
		HwDataOverrunstationOverweight Overweight = dataOverrunstationOverweightMapper.selectOne(entity);
		// 按钮提交后需再次验证上述条件是否成立（成立执行，不成立，返回提示“该车辆信息不能进行查扣处理！”；
		if (!(Overweight.getIsSeized() == 0)) {
			return ResponeResultUtil.fail(HWSystemCode.DATAIN);
		} else {
			Wrapper<HwDataOverrunstationOverweight> stationStorywrapper = new EntityWrapper<HwDataOverrunstationOverweight>();
			stationStorywrapper.eq("F_Id", fId);
			HwDataOverrunstationOverweight NewEntity = new HwDataOverrunstationOverweight();
			NewEntity.setIsSeized(1);// 是否查扣（0未查扣，1查扣），默认0
			NewEntity.setIsSeizedtime(new Timestamp(System.currentTimeMillis()));// 查扣时间
			NewEntity.setIsSeizedaccount(vo.getIsSeizedaccount());// 操作人员（当前用户）
			Integer update = dataOverrunstationOverweightMapper.update(NewEntity, stationStorywrapper);
			if (update != 1) {
				return ResponeResultUtil.fail(HWSystemCode.FAIL);
			}
			// 4.2、往执法表插入执法数据； 执法表
			HwCaseMain hwCaseMain=new HwCaseMain();
			String number = RandomNumberUtil.getNumber();
			hwCaseMain.setfCaseid(number);//主键
			hwCaseMain.setfOverrunid(Overweight.getfId());//称重Id
			hwCaseMain.setFareacode(Overweight.getfAreacode());
			hwCaseMain.setfOverruncode(Overweight.getfOverruncode());//检测站编码
			hwCaseMain.setfOverrunname(Overweight.getfOverrunname());//检测站名称（站）
			hwCaseMain.setfClTruckno(Overweight.getCph());//车牌号F_CL_TruckNo
            Integer integer = Overweight.getdZs();
            if (integer!=null){
                hwCaseMain.setfClAxis(Overweight.getdZs().toString()); //F_CL_Axis轴数 1
            }
			hwCaseMain.setfClTotalweight(Overweight.getjZz());  //总重(静态称重)
            Integer integer1 = Overweight.getdXz();
            if (integer1!=null){
                hwCaseMain.setfClLimitweight(Overweight.getdXz().doubleValue()); //限重
            }
			hwCaseMain.setfClOverweight(Overweight.getjCxds());//超重
			hwCaseMain.setfClXz(Overweight.getjCxds());//卸裁重量
			hwCaseMain.setfClOverrate(Overweight.getdCxl());//   超限率
			hwCaseMain.setfClChecktime(Overweight.getjJcsj()); //检查时间1(称重表静态时间)
			hwCaseMain.setfAjCrtstep("01");//  F_AJ_CrtStep
			hwCaseMain.setfAjInvestigate(0); // F_AJ_Investigate
			hwCaseMain.setfAjPolice(0); // F_AJ_Police
			hwCaseMain.setfAjGostate(0);// F_AJ_GoState 放行状态（正常-0|超时-1）0
			hwCaseMain.setfAjSupervisestate(0);//F_AJ_SuperviseState 督导状态（是-1|否-0）0
			hwCaseMain.setfAjReturntimes(0);// F_AJ_ReturnTimes 退回次数（默认:0）
			hwCaseMain.setfSrcgoodsunload(vo.getNameBoard()); //F_SrcGoodsUnload 卸载地（站点名称）
			hwCaseMain.setFcreatetime(new Timestamp(System.currentTimeMillis()));
			Integer insert = hwCaseMainMapper.insert(hwCaseMain);
			if (insert!=1){
				return ResponeResultUtil.fail(HWSystemCode.FAIL);
			}
//            // 4.3、往“审批操作过程表”中插入对应审批数据；
//            HwCommandTask hwCommandTask = hwCommandTaskMapper.selectById(taskId);
			// 创建各阶段审批操作过程
			HwCommandWorkflow hwCommandWorkflow = new HwCommandWorkflow();
			hwCommandWorkflow.setCommandworkflowId(RandomNumberUtil.getNumber());
			hwCommandWorkflow.setWorkflowModule("02");
			hwCommandWorkflow.setWorkflowType("SHZF");
			hwCommandWorkflow.setWorkflowCode("00");
			hwCommandWorkflow.setWorkflowCodename("待查扣");
			hwCommandWorkflow.setCommandworkflowButtonname(vo.getButtonName());
			hwCommandWorkflow.setfAccount(vo.getfAccount());
			hwCommandWorkflow.setfFromdepcode(vo.getfFromdepcode());
			hwCommandWorkflow.setfFromdepname(vo.getfFromdepname());
			hwCommandWorkflow.setCommandworkflowDatatime(new Date());
//			hwCommandWorkflow.setCommandworkflowContent(vo.getTaskContent());
			hwCommandWorkflow.setObjectId(number);
			hwCommandWorkflow.setWorkflowNextcode("01");
			hwCommandWorkflow.setWorkflowNextcodename("待立案");
			// (4.2)各审批操作过程表，插入内容：全部，对应异地复检处理
			// 向各阶段审批操作过程表插入数据
			boolean success = commandWorkflowService.addWorkflow(hwCommandWorkflow);
			if (success == false) {
				// 事务回滚
				throw new HWSystemException();
			}
		}
		return ResponeResultUtil.success(HWSystemCode.SUCCESS);
	}


	/**
	 * 站的指挥调度-闯卡移交
	 *
	 * @param vo
	 *            RUSCARD
	 * @return
	 */
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { Exception.class, RuntimeException.class,
			HWSystemException.class })
	public Map<String, Object> rusCard(StandCommandTaskVo vo) {
		// 超重车辆表 的 GUID
		String fId = vo.getfId();
		HwCommandTask entity = new HwCommandTask();
		entity.setfId(fId);
		HwCommandTask hwCommandTask = hwCommandTaskMapper.selectOne(entity);

		HwDataOverrunstationOverweight hwDataOverrunstationOverweight = new HwDataOverrunstationOverweight();
		hwDataOverrunstationOverweight.setfId(fId);
		HwDataOverrunstationOverweight Overweight = dataOverrunstationOverweightMapper
				.selectOne(hwDataOverrunstationOverweight);
		// 按钮提交后需再次验证上述条件是否成立（成立执行，不成立，返回提示“该车辆信息不能进行查扣处理！”；
		if (!(hwCommandTask == null && Overweight.getIsSeized() == 0)) {
			return ResponeResultUtil.fail(HWSystemCode.RUSCARD);
		}
		// 4.1、对指挥调度任务表进行插入操作,插入内容：
		HwCommandTask newTask = new HwCommandTask();
		newTask.setTaskId(RandomNumberUtil.getNumber());
		newTask.setfId(vo.getfId());
		newTask.setTaskClass(1);
		newTask.setTaskType("02");
		newTask.setTaskContent(vo.getTaskContent());
		newTask.setfFromdeptype(3);
		newTask.setfFromdepcode(vo.getfFromdepcode());
		newTask.setfFromdepname(vo.getfFromdepname());
		newTask.setfAreacode(vo.getfAreacode());
		newTask.setfAccount(vo.getfAccount());
		newTask.setfCreatetime(new Timestamp(System.currentTimeMillis()));
		newTask.setFlowCode("YJ");
		HwBaseWorkflow startBaseWorkflow = baseWorkflowService.getStartBaseWorkflow("YJ");
		newTask.setFlowStage(startBaseWorkflow.getWorkflowNextcode());
		// newTask.setFlowStage("03");
		newTask.setAssignState(0);
		newTask.setIsStagestate(0);
		Integer insert = hwCommandTaskMapper.insert(newTask);
		if (insert != 1) {
			return ResponeResultUtil.fail(HWSystemCode.FAIL);
		}
		HwCommandTask commandTask=new HwCommandTask();
		commandTask.setfId(fId);
		HwCommandTask CommandTask = hwCommandTaskMapper.selectOne(commandTask);
//		// 办理阶段
//		String flowStage = "01";
//		// 流程类型编号
//		String flowCode = CommandTask.getFlowCode();
//		HwBaseWorkflow presentWorkflow = baseWorkflowService.getPresentWorkflow(flowStage, flowCode);
		// 创建各阶段审批操作过程
		HwCommandWorkflow hwCommandWorkflow = new HwCommandWorkflow();
		hwCommandWorkflow.setCommandworkflowId(RandomNumberUtil.getNumber());
		hwCommandWorkflow.setWorkflowModule(startBaseWorkflow.getWorkflowModule());
		hwCommandWorkflow.setWorkflowType(startBaseWorkflow.getWorkflowType());  //workflowType
		hwCommandWorkflow.setWorkflowCode(startBaseWorkflow.getWorkflowCode());
		hwCommandWorkflow.setWorkflowCodename(startBaseWorkflow.getWorkflowCodename());
		hwCommandWorkflow.setCommandworkflowButtonname(vo.getButtonName());
		hwCommandWorkflow.setfAccount(vo.getfAccount());
		hwCommandWorkflow.setfFromdepcode(vo.getfFromdepcode());
		hwCommandWorkflow.setfFromdepname(vo.getfFromdepname());
		hwCommandWorkflow.setCommandworkflowDatatime(new Date());
//		hwCommandWorkflow.setCommandworkflowContent(vo.getTaskContent());
		hwCommandWorkflow.setObjectId(CommandTask.getTaskId());
		hwCommandWorkflow.setWorkflowNextcode(startBaseWorkflow.getWorkflowNextcode());
		hwCommandWorkflow.setWorkflowNextcodename(startBaseWorkflow.getWorkflowNextcodename());
		// (4.2)各审批操作过程表，插入内容：全部，对应异地复检处理
		// 向各阶段审批操作过程表插入数据
		boolean success = commandWorkflowService.addWorkflow(hwCommandWorkflow);
		if (success == false) {
			// 事务回滚
			throw new HWSystemException();
		}
		return ResponeResultUtil.success(HWSystemCode.SUCCESS);
	}

	/**
	 * Rushcard 站的指挥调度-逃逸移交
	 *
	 * @param vo
	 * @return
	 */
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { Exception.class, RuntimeException.class,
			HWSystemException.class })
	public Map<String, Object> transferOfEscape(StandCommandTaskVo vo) {
		// 超重车辆表 的 GUID
		String fId = vo.getfId();
		HwCommandTask entityTask = new HwCommandTask();
		entityTask.setfId(fId);
		HwCommandTask hwCommandTask = hwCommandTaskMapper.selectOne(entityTask);

		HwDataOverrunstationOverweight entityWeight = new HwDataOverrunstationOverweight();
		entityWeight.setfId(fId);
		HwDataOverrunstationOverweight Overweight = dataOverrunstationOverweightMapper.selectOne(entityWeight);
		// 按钮显示条件：按钮显示条件：本站+复检数据超重+未查扣（IS_Seized=0）+未处理；
		if (!(hwCommandTask == null && Overweight.getIsSeized() == 0)) {
			// 按钮提交后需再次验证上述条件是否成立（成立执行，不成立，返回提示“该车辆信息不能进行逃逸移交处理
			return ResponeResultUtil.fail(HWSystemCode.TRANSFER_OF_ESCAPE);
		} else {
			// 4.1、对指挥调度任务表进行插入操作,插入内容：
			HwCommandTask entity = new HwCommandTask();
			entity.setTaskId(RandomNumberUtil.getNumber());
			entity.setfId(vo.getfId());
			entity.setTaskClass(1);
			entity.setTaskType("03");
			entity.setTaskContent(vo.getTaskContent());
			entity.setfFromdeptype(3);
			entity.setfFromdepcode(vo.getfFromdepcode());
			entity.setfFromdepname(vo.getfFromdepname());
			entity.setfAreacode(vo.getfAreacode());
			entity.setfAccount(vo.getfAccount());
			entity.setfCreatetime(new Timestamp(System.currentTimeMillis()));
			entity.setFlowCode("YJ");
			HwBaseWorkflow startBaseWorkflow = baseWorkflowService.getStartBaseWorkflow("YJ");
			entity.setFlowStage(startBaseWorkflow.getWorkflowNextcode());
//			entity.setFlowStage("03");
			entity.setAssignState(0);
			entity.setIsStagestate(0);
			Integer insert = hwCommandTaskMapper.insert(entity);
			if (insert != 1) {
				return ResponeResultUtil.fail(HWSystemCode.FAIL);
			}
			HwCommandTask commandTask=new HwCommandTask();
			commandTask.setfId(fId);
			HwCommandTask CommandTask = hwCommandTaskMapper.selectOne(commandTask);
			// 办理阶段
//			String flowStage = "01";
//			// 流程类型编号
//			String flowCode = CommandTask.getFlowCode();
//			HwBaseWorkflow presentWorkflow = baseWorkflowService.getPresentWorkflow(flowStage, flowCode);
			// 创建各阶段审批操作过程
			HwCommandWorkflow hwCommandWorkflow = new HwCommandWorkflow();
			hwCommandWorkflow.setCommandworkflowId(RandomNumberUtil.getNumber());
			hwCommandWorkflow.setWorkflowModule(startBaseWorkflow.getWorkflowModule());
			hwCommandWorkflow.setWorkflowType(startBaseWorkflow.getWorkflowType());  //workflowType
			hwCommandWorkflow.setWorkflowCode(startBaseWorkflow.getWorkflowCode());
			hwCommandWorkflow.setWorkflowCodename(startBaseWorkflow.getWorkflowCodename());
			hwCommandWorkflow.setCommandworkflowButtonname(vo.getButtonName());
			hwCommandWorkflow.setfAccount(vo.getfAccount());
			hwCommandWorkflow.setfFromdepcode(vo.getfFromdepcode());
			hwCommandWorkflow.setfFromdepname(vo.getfFromdepname());
			hwCommandWorkflow.setCommandworkflowDatatime(new Date());
//			hwCommandWorkflow.setCommandworkflowContent(vo.getTaskContent());
			hwCommandWorkflow.setObjectId(CommandTask.getTaskId());
			hwCommandWorkflow.setWorkflowNextcode(startBaseWorkflow.getWorkflowNextcode());
			hwCommandWorkflow.setWorkflowNextcodename(startBaseWorkflow.getWorkflowNextcodename());
			// 4.2、各审批操作过程表，插入内容：全部,对应逃逸标志
			// 向各阶段审批操作过程表插入数据
			boolean success = commandWorkflowService.addWorkflow(hwCommandWorkflow);
			if (success == false) {
				// 事务回滚
				throw new HWSystemException();
			}
			return ResponeResultUtil.success(HWSystemCode.SUCCESS);
		}
	}

	/**
	 * 站的指挥调度-情况说明（待确定）
	 *
	 * @param vo
	 * @return
	 */
	public Map<String, Object> presentation(StepInfoVO vo) {
		//0 正常 1 退回  2延期
		Integer workflowDoresult = vo.getWorkflowDoresult();
		// 超重车辆表 的 GUID
		String fId = vo.getfId();
		HwCommandTask entityhwCommandTask = new HwCommandTask();
		entityhwCommandTask.setfId(fId);
		HwCommandTask hwCommandTask = hwCommandTaskMapper.selectOne(entityhwCommandTask);
		String flowStage = hwCommandTask.getFlowStage();
		String taskType = hwCommandTask.getTaskType();
		// 按钮显示条件：指挥调度任务表中办理阶段为待说明（Flow_Stage=03），任务类型为闯卡移交或逃逸移交（Task_Type='02'//
		// or Task_Type='03')
		if (!("03".equals(flowStage) && ("02".equals(taskType) || "03".equals(taskType)))) {
			return ResponeResultUtil.fail(HWSystemCode.PRESENTATION);
		} else {
			// 附件表新增
			String folderId = RandomNumberUtil.getNumber(); //Task_ExplainFile
			HwCommandTask newTask = new HwCommandTask();
			// 正常
			if (workflowDoresult==0){
				newTask.setFlowStage(vo.getWorkflowNextcode());
				newTask.setIsStagestate(vo.getWorkflowDoresult());
				newTask.setTaskExplainfile(folderId); //Task_ExplainFile
				// 更新条件
				Wrapper<HwCommandTask> wrapper = new EntityWrapper<HwCommandTask>();
				wrapper.eq("Task_ID", vo.getTaskId());
				Integer update = hwCommandTaskMapper.update(newTask, wrapper);
				if (update != 1) {
					return ResponeResultUtil.fail(HWSystemCode.FAIL);
				}
			}
			//退回
			if (workflowDoresult==1){
				newTask.setFlowStage(vo.getWorkflowNextcode());
				newTask.setIsStagestate(vo.getWorkflowDoresult());
				// 更新条件
				Wrapper<HwCommandTask> wrapper = new EntityWrapper<HwCommandTask>();
				wrapper.eq("Task_ID", vo.getTaskId());
				Integer update = hwCommandTaskMapper.update(newTask, wrapper);
				if (update != 1) {
					return ResponeResultUtil.fail(HWSystemCode.FAIL);
				}
			}

			List<FileInfo> fileInfoList = vo.getFileInfoList();
			int i =0;
			for (FileInfo fileInfo : fileInfoList) {
				++i;
				HwBaseAnnexesfile hwBaseAnnexesfile = new HwBaseAnnexesfile();
				hwBaseAnnexesfile.setFileId(RandomNumberUtil.getNumber());
				hwBaseAnnexesfile.setfFolderid(folderId);
				hwBaseAnnexesfile.setFileType(fileInfo.getFileType());
//				hwBaseAnnexesfile.setFileName(vo.getFileName()+String.valueOf(i));
				hwBaseAnnexesfile.setFileName("情况说明附件"+String.valueOf(i));
				hwBaseAnnexesfile.setFilePath(fileInfo.getFilePath());
				hwBaseAnnexesfile.setFileSize(fileInfo.getFileSize());
				hwBaseAnnexesfile.setFileMoudletype("ZHDDFILE指挥调度");
				hwBaseAnnexesfile.setfCreateuserid(vo.getfFromdepcode());
				hwBaseAnnexesfile.setfCreatedate(new Timestamp(System.currentTimeMillis()));
				hwBaseAnnexesfile.setfCreateusername(vo.getLoginUser());
				Integer insert = hwBaseAnnexesfileMapper.insert(hwBaseAnnexesfile);
				if (insert != 1) {
					return ResponeResultUtil.fail(HWSystemCode.FAIL);
				}
			}
			// 4、各审批操作过程表，插入内容：全部
			// 创建各阶段审批操作过程
			HwCommandWorkflow hwCommandWorkflow = new HwCommandWorkflow();
			hwCommandWorkflow.setCommandworkflowId(RandomNumberUtil.getNumber());
			hwCommandWorkflow.setWorkflowModule(vo.getWorkflowModule());
			//当前阶段 所属流程
			hwCommandWorkflow.setWorkflowType(vo.getWorkflowType());
			//当前阶段编号
			hwCommandWorkflow.setWorkflowCode(vo.getWorkflowCode());
			hwCommandWorkflow.setWorkflowCodename(vo.getWordflowCodename());
			hwCommandWorkflow.setCommandworkflowButtonname(vo.getButtonName());
			hwCommandWorkflow.setfAccount(vo.getLoginUser());
			hwCommandWorkflow.setfFromdepcode(vo.getDeptCode());
			hwCommandWorkflow.setfFromdepname(vo.getDeptName());
			hwCommandWorkflow.setCommandworkflowDatatime(new Date());
			hwCommandWorkflow.setCommandworkflowContent(vo.getContent());
			hwCommandWorkflow.setObjectId(hwCommandTask.getTaskId());
			hwCommandWorkflow.setfAnnexes(folderId);
			hwCommandWorkflow.setWorkflowNextcode(vo.getWorkflowNextcode());
			hwCommandWorkflow.setWorkflowNextcodename(vo.getWorkflowNextname());
			// 向各阶段审批操作过程表插入数据
			boolean success = commandWorkflowService.addWorkflow(hwCommandWorkflow);
			if (success == false) {
				throw new HWSystemException();
			}
		}
		return ResponeResultUtil.success(HWSystemCode.SUCCESS);
	}

	/**
	 * 站的指挥调度-上报视频
	 *
	 * @param vo
	 * @return
	 */
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { Exception.class, RuntimeException.class,
			HWSystemException.class })
	public Map<String, Object> reportedVideo(StandCommandTaskVo vo) {
		// 超重车辆表 的 GUID
		String fId = vo.getfId();
		HwCommandTask entityhwCommandTask = new HwCommandTask();
		entityhwCommandTask.setfId(fId);
		HwCommandTask hwCommandTask = hwCommandTaskMapper.selectOne(entityhwCommandTask);
		String flowStage = hwCommandTask.getFlowStage();
		String taskType = hwCommandTask.getTaskType();
		String flowCode = hwCommandTask.getFlowCode();
		// 按钮提交后需再次验证上述条件是否成立 、
		// 按钮显示条件：本站指挥调度任务表中办理阶段为待说明、待确认、待移交、待完结（Flow_Stage=03OR05or06or07）
		// ，任务类型为闯卡移交或逃逸移交（Task_Type='02' or Task_Type='03')；
		if (("03".equals(flowStage) || "05".equals(flowStage) || "06".equals(flowStage) || "07".equals(flowStage))
				&& ("02".equals(taskType) || "03".equals(taskType))) {
			// 获取视频可上传多条,单条
			List<FileInfo> fileInfoList = vo.getFileInfoList();
			// 附件表新增
			String folderId = RandomNumberUtil.getNumber();//Task_VideoFile
			int add =0;
			// 多条,单条视频路径
			for (FileInfo fileInfo : fileInfoList) {
				++add;
				HwBaseAnnexesfile hwBaseAnnexesfile = new HwBaseAnnexesfile();
				hwBaseAnnexesfile.setFileId(RandomNumberUtil.getNumber());
				// 业务表附件组GUID
				hwBaseAnnexesfile.setfFolderid(folderId);
				hwBaseAnnexesfile.setFileType(fileInfo.getFileType());
			//	hwBaseAnnexesfile.setFileName(vo.getFileName()+String.valueOf(i));
				hwBaseAnnexesfile.setFileName("视频附件"+String.valueOf(add));
				hwBaseAnnexesfile.setFilePath(fileInfo.getFilePath());
				hwBaseAnnexesfile.setFileSize(fileInfo.getFileSize());
				hwBaseAnnexesfile.setfCreateuserid(vo.getfFromdepcode());
				hwBaseAnnexesfile.setFileMoudletype("ZHDDFILE指挥调度");
				hwBaseAnnexesfile.setfCreatedate(new Timestamp(System.currentTimeMillis()));
				hwBaseAnnexesfile.setfCreateusername(vo.getfCreateusername());
				Integer insert = hwBaseAnnexesfileMapper.insert(hwBaseAnnexesfile);
				if (insert != 1) {
					throw new HWSystemException();
				}
			}
			// 查询下一步的工作流code
			HwBaseWorkflow hwBaseWorkflow = baseWorkflowService.getPresentWorkflow(flowStage, flowCode);
////		String nextFlowStage = hwBaseWorkflow.getWorkflowNextcode();
//			String nextFlowCodeName = hwBaseWorkflow.getWorkflowNextcodename();
			Wrapper<HwCommandTask> wrapper = new EntityWrapper<HwCommandTask>();
			wrapper.eq("Task_ID", hwCommandTask.getTaskId());
			// 办理阶段
//			hwCommandTask.setFlowStage(nextFlowStage);
			// 视频附件（多人视频）附件GUID
			hwCommandTask.setTaskVideofile(folderId);
			Integer update = hwCommandTaskMapper.update(hwCommandTask, wrapper);
			if (update != 1) {
				throw new HWSystemException();
			}
			// 4、各审批操作过程表，插入内容：全部
			// 创建各阶段审批操作过程
			HwCommandWorkflow hwCommandWorkflow = new HwCommandWorkflow();
			hwCommandWorkflow.setCommandworkflowId(RandomNumberUtil.getNumber());
			hwCommandWorkflow.setWorkflowModule(hwBaseWorkflow.getWorkflowModule());
			hwCommandWorkflow.setWorkflowType(hwBaseWorkflow.getWorkflowType());
			hwCommandWorkflow.setWorkflowCode(hwBaseWorkflow.getWorkflowCode());
			hwCommandWorkflow.setWorkflowCodename(hwBaseWorkflow.getWorkflowCodename());
			hwCommandWorkflow.setCommandworkflowButtonname(vo.getButtonName());
			hwCommandWorkflow.setfAccount(vo.getfAccount());
			hwCommandWorkflow.setfFromdepcode(vo.getfFromdepcode());
			hwCommandWorkflow.setfFromdepname(vo.getfFromdepname());
			hwCommandWorkflow.setCommandworkflowDatatime(new Date());
//			hwCommandWorkflow.setCommandworkflowContent(vo.getTaskContent());
			hwCommandWorkflow.setObjectId(hwCommandTask.getTaskId());
			hwCommandWorkflow.setfAnnexes(folderId);
			//2019年11月24日16:32:42 原总说暂时不用 下一步状态是99 不在范围
			hwCommandWorkflow.setWorkflowNextcode("99");
//			hwCommandWorkflow.setWorkflowNextcodename(nextFlowCodeName);
			// 向各阶段审批操作过程表插入数据
			boolean success = commandWorkflowService.addWorkflow(hwCommandWorkflow);
			if (success == false) {
				throw new HWSystemException();
			}
			return ResponeResultUtil.success(HWSystemCode.SUCCESS);
		} else {
			return ResponeResultUtil.fail(HWSystemCode.REPORTEDVIDEO);
		}

	}

	/**
	 * 上报移交单 （待确定）
	 *
	 * @param vo
	 * @param
	 * @return
	 */
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { Exception.class, RuntimeException.class,
			HWSystemException.class })
	public Map<String, Object> submitDelivery(StepInfoVO vo) {
		//0 正常 1 退回  2延期
		Integer workflowDoresult = vo.getWorkflowDoresult();
		// 超重车辆表 的 GUID
		String fId = vo.getfId();
		HwCommandTask entityhwCommandTask = new HwCommandTask();
		entityhwCommandTask.setfId(fId);
		HwCommandTask hwCommandTask = hwCommandTaskMapper.selectOne(entityhwCommandTask);
		String flowStage = hwCommandTask.getFlowStage();
		String taskType = hwCommandTask.getTaskType();
		// 显示条件：本站指挥调度任务表中办理阶段为待移交（Flow_Stage=06），任务类型为闯卡移交或逃逸移交（Task_Type='02'
		// or Task_Type='03')；
		// 保存按钮提交后需再次验证上述条件是否成立（成立执行，不成立，返回提示“该车辆信息不能进行上报移交单！”；
		if ("06".equals(flowStage) && ("02".equals(taskType) || "03".equals(taskType))) {
			// 附件表新增
			String folderId = RandomNumberUtil.getNumber();
			HwCommandTask newTask = new HwCommandTask();
			// 正常
			if (workflowDoresult==0){
				newTask.setFlowStage(vo.getWorkflowNextcode());
				newTask.setIsStagestate(vo.getWorkflowDoresult());
				newTask.setTaskTransferfile(folderId);
				// 更新条件
				Wrapper<HwCommandTask> wrapper = new EntityWrapper<HwCommandTask>();
				wrapper.eq("Task_ID", vo.getTaskId());
				Integer update = hwCommandTaskMapper.update(newTask, wrapper);
				if (update != 1) {
					return ResponeResultUtil.fail(HWSystemCode.FAIL);
				}
			}
			//退回
			if (workflowDoresult==1){
				newTask.setFlowStage(vo.getWorkflowNextcode());
				newTask.setIsStagestate(vo.getWorkflowDoresult());
				// 更新条件
				Wrapper<HwCommandTask> wrapper = new EntityWrapper<HwCommandTask>();
				wrapper.eq("Task_ID", vo.getTaskId());
				Integer update = hwCommandTaskMapper.update(newTask, wrapper);
				if (update != 1) {
					return ResponeResultUtil.fail(HWSystemCode.FAIL);
				}
			}
			List<FileInfo> fileInfoList = vo.getFileInfoList();
			int i=0;
			for (FileInfo fileInfo : fileInfoList) {
				++i;
				//插入附件
				HwBaseAnnexesfile hwBaseAnnexesfile = new HwBaseAnnexesfile();
				hwBaseAnnexesfile.setFileId(RandomNumberUtil.getNumber());
				hwBaseAnnexesfile.setfFolderid(folderId);
				hwBaseAnnexesfile.setFileType(fileInfo.getFileType());
				//hwBaseAnnexesfile.setFileName(vo.getFileName()+String.valueOf(i));
				hwBaseAnnexesfile.setFileName("上报移交单"+String.valueOf(i));
				hwBaseAnnexesfile.setFilePath(fileInfo.getFilePath());
				hwBaseAnnexesfile.setfCreateuserid(vo.getfFromdepcode());
				hwBaseAnnexesfile.setFileSize(fileInfo.getFileSize());
				hwBaseAnnexesfile.setFileMoudletype("ZHDDFILE指挥调度");
				hwBaseAnnexesfile.setfCreatedate(new Timestamp(System.currentTimeMillis()));
				hwBaseAnnexesfile.setfCreateusername(vo.getfCreateusername());
				Integer insert = hwBaseAnnexesfileMapper.insert(hwBaseAnnexesfile);
				if (insert != 1) {
					return ResponeResultUtil.fail(HWSystemCode.FAIL);
				}
			}
			// 各审批操作过程表，插入内容：全部,对应待说明标志操作
			// 创建各阶段审批操作过程
			HwCommandWorkflow hwCommandWorkflow = new HwCommandWorkflow();
			hwCommandWorkflow.setCommandworkflowId(RandomNumberUtil.getNumber());
			hwCommandWorkflow.setWorkflowModule(vo.getWorkflowModule());
			hwCommandWorkflow.setWorkflowType(vo.getWorkflowType());
			hwCommandWorkflow.setWorkflowCode(vo.getWorkflowCode());
			hwCommandWorkflow.setWorkflowCodename(vo.getWordflowCodename());
			hwCommandWorkflow.setCommandworkflowButtonname(vo.getButtonName());
			hwCommandWorkflow.setfAccount(vo.getLoginUser());
			hwCommandWorkflow.setfFromdepcode(vo.getDeptCode());
			hwCommandWorkflow.setfFromdepname(vo.getDeptName());
			hwCommandWorkflow.setCommandworkflowDatatime(new Date());
			hwCommandWorkflow.setCommandworkflowContent(vo.getContent());
			hwCommandWorkflow.setObjectId(hwCommandTask.getTaskId());
			hwCommandWorkflow.setfAnnexes(folderId);
			hwCommandWorkflow.setWorkflowNextcode(vo.getWorkflowNextcode());
			hwCommandWorkflow.setWorkflowNextcodename(vo.getWorkflowNextname());
			// 向各阶段审批操作过程表插入数据
			boolean success = commandWorkflowService.addWorkflow(hwCommandWorkflow);
			if (success == false) {
				throw new HWSystemException();
			}
		} else {
			// 该车辆信息不能进行上报移交单！
			return ResponeResultUtil.fail(HWSystemCode.SUBMIT_DELIVERY);
		}
		return ResponeResultUtil.success(HWSystemCode.SUCCESS);
	}

	/**
	 * 确认移交 （待确定）
	 *
	 * @param vo
	 * @return
	 */
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { Exception.class, RuntimeException.class,
			HWSystemException.class })
	public Map<String, Object> confirmTheTransfer( StepInfoVO vo) {
		//0 正常 1 退回  2延期
		Integer workflowDoresult = vo.getWorkflowDoresult();
		String fId = vo.getfId();
		HwCommandTask entityHwCommandTask = new HwCommandTask();
		entityHwCommandTask.setfId(fId);
		HwCommandTask hwCommandTask = hwCommandTaskMapper.selectOne(entityHwCommandTask);
		String flowStage = hwCommandTask.getFlowStage();
		String taskType = hwCommandTask.getTaskType();
		// 显示条件：指挥调度任务表中办理阶段为待完结（Flow_Stage=07），
		// 任务类型为闯卡移交或逃逸移交（Task_Type='02' or
		// Task_Type='03')，情况说明附件已上传，视频附件已上传,移交单附件已上传；
		if ("07".equals(flowStage) && ("02".equals(taskType) || "03".equals(taskType))) {
			//Task_ExplainFile  Task_VideoFile Task_TransferFile Task_EndFile
			  if (hwCommandTask.getTaskVideofile()!=null){
				  // 附件表新增
				  String folderId = RandomNumberUtil.getNumber();
				  HwCommandTask newTask = new HwCommandTask();
				  // 正常
				  if (workflowDoresult==0){
					  newTask.setFlowStage(vo.getWorkflowNextcode());
					  newTask.setIsStagestate(vo.getWorkflowDoresult());
					  newTask.setTaskEndtime(new Timestamp(System.currentTimeMillis()));
					  newTask.setTaskEndaccount(vo.getfAccount());
					  newTask.setTaskEnddepcode(vo.getDeptCode());
					  newTask.setTaskEnddepname(vo.getDeptName());
					  newTask.setTaskContent(vo.getContent());
					  newTask.setTaskEndfile(folderId);
					  // 更新条件
					  Wrapper<HwCommandTask> wrapper = new EntityWrapper<HwCommandTask>();
					  wrapper.eq("Task_ID", vo.getTaskId());
					  Integer update = hwCommandTaskMapper.update(newTask, wrapper);
					  if (update != 1) {
						  return ResponeResultUtil.fail(HWSystemCode.FAIL);
					  }
				  }
				  //退回
				  if (workflowDoresult==1){
					  newTask.setFlowStage(vo.getWorkflowNextcode());
					  newTask.setIsStagestate(vo.getWorkflowDoresult());
					  // 更新条件
					  Wrapper<HwCommandTask> wrapper = new EntityWrapper<HwCommandTask>();
					  wrapper.eq("Task_ID", vo.getTaskId());
					  Integer update = hwCommandTaskMapper.update(newTask, wrapper);
					  if (update != 1) {
						  return ResponeResultUtil.fail(HWSystemCode.FAIL);
					  }
				  }
				  // 各审批操作过程表，插入内容：全部,对应待说明标志操作
				  // 创建各阶段审批操作过程
				  HwCommandWorkflow hwCommandWorkflow = new HwCommandWorkflow();
				  hwCommandWorkflow.setCommandworkflowId(RandomNumberUtil.getNumber());
				  hwCommandWorkflow.setWorkflowModule(vo.getWorkflowModule());
				  hwCommandWorkflow.setWorkflowType(vo.getWorkflowType());
				  hwCommandWorkflow.setWorkflowCode(vo.getWorkflowCode());
				  hwCommandWorkflow.setWorkflowCodename(vo.getWordflowCodename());
				  hwCommandWorkflow.setCommandworkflowButtonname(vo.getButtonName());
				  hwCommandWorkflow.setfAccount(vo.getLoginUser());
				  hwCommandWorkflow.setfFromdepcode(vo.getDeptCode());
				  hwCommandWorkflow.setfFromdepname(vo.getDeptName());
				  hwCommandWorkflow.setCommandworkflowDatatime(new Date());
				  hwCommandWorkflow.setCommandworkflowContent(vo.getContent());
//				  hwCommandWorkflow.setCommandworkflowContent(vo.getTaskContent());
				  hwCommandWorkflow.setObjectId(vo.getTaskId());
				  hwCommandWorkflow.setfAnnexes(folderId);
				  hwCommandWorkflow.setWorkflowNextcode(vo.getWorkflowNextcode());
				  hwCommandWorkflow.setWorkflowNextcodename(vo.getWorkflowNextname());
				  boolean success = commandWorkflowService.addWorkflow(hwCommandWorkflow);
				  if (success == false) {
					  throw new HWSystemException();
				  }
			  }else {
				  return ResponeResultUtil.fail(HWSystemCode.TRANSFER_FILE_EXIT);
			  }
		 } else {
			// 该车辆信息不能进行确认移交！
			return ResponeResultUtil.fail(HWSystemCode.CONFIRM_THE_TRANSFER);
		}
		return ResponeResultUtil.success(HWSystemCode.SUCCESS);
	}

	/**
	 * 详情 Confirm the transfer
	 *
	 * @param
	 * @return
	 */
	public Map<String, Object> detail(String fid) {

		HashMap<String, Object> result = new HashMap<String, Object>();
		// 超重数据
		HwDataOverrunstationOverweight weight = dataOverrunstationOverweightMapper.selectById(fid);

		//调度表
		HwCommandTask hwCommandTask=new HwCommandTask();
		hwCommandTask.setfId(weight.getfId());
		HwCommandTask hwCommandTask1 = hwCommandTaskMapper.selectOne(hwCommandTask);
		if (hwCommandTask1!=null){
			//调度督导表
			HwSupervision hwSupervision=new HwSupervision();
			EntityWrapper<HwSupervision> supervision = new EntityWrapper<HwSupervision>();
			supervision.eq("F_FromObjectID",hwCommandTask1.getTaskId());
			List<HwSupervision> hwSupervisions = hwSupervisionMapper.selectList(supervision);
			List<SupervisionVo> supervisionVo =new ArrayList<>();
			for (HwSupervision hwSupervision1 : hwSupervisions) {
				SupervisionVo supervisionVo1= new SupervisionVo();
				supervisionVo1.setfSpvid(hwSupervision1.getfSpvid());
				supervisionVo1.setfFromobjectid(hwSupervision1.getfFromobjectid());
				supervisionVo1.setfFromtype(hwSupervision1.getfFromtype());
				supervisionVo1.setfFromdepcode(hwSupervision1.getfFromdepcode());
				supervisionVo1.setfFromuserid(hwSupervision1.getfFromuserid());
				supervisionVo1.setfFromusername(hwSupervision1.getfFromusername());
				supervisionVo1.setfFromtime(hwSupervision1.getfFromtime());
				supervisionVo1.setfTitle(hwSupervision1.getfTitle());
				supervisionVo1.setfFromsrc(hwSupervision1.getfFromsrc());
				supervisionVo1.setfSpvcontent(hwSupervision1.getfSpvcontent());
				supervisionVo1.setfCurrentstep(hwSupervision1.getfCurrentstep());
				supervisionVo1.setfBacktype(hwSupervision1.getfBacktype());
				supervisionVo1.setfBackdepcode(hwSupervision1.getfBackdepcode());
				supervisionVo1.setfBackdepname(hwSupervision1.getfBackdepname());
				supervisionVo1.setfBackuserid(hwSupervision1.getfBackuserid());
				supervisionVo1.setfBackusername(hwSupervision1.getfBackusername());
				supervisionVo1.setfBackuserphone(hwSupervision1.getfBackuserphone());
				supervisionVo1.setfBacktime(hwSupervision1.getfBacktime());
				supervisionVo1.setfBackfile(hwSupervision1.getfBackfile());
				supervisionVo1.setfBackassignstate(hwSupervision1.getfBackassignstate());
				supervisionVo1.setIsStagestate(hwSupervision1.getIsStagestate());
				//附件表
				EntityWrapper<HwBaseAnnexesfile> annexesFile = new EntityWrapper<HwBaseAnnexesfile>();
				annexesFile.eq("F_FolderId",hwSupervision1.getfBackfile());
				List<HwBaseAnnexesfile> list = hwBaseAnnexesfileMapper.selectList(annexesFile);
				supervisionVo1.setFuJan(list);
				supervisionVo.add(supervisionVo1);
			}
			result.put("weighingData",weight);
			//调度督导表
			result.put("checkTheSupervision",supervisionVo);
		}else {
			// 车辆的图片
			result.put("weighingData",weight);
		}
		// 车辆的图片

		return ResponeResultUtil.successNotice(HWSystemCode.SUCCESS, result);

	}





	/**
	 * 详情 Confirm the transfer
	 * @param
	 * @return
	 */
	public Map<String, Object> details(String fid) {
		HashMap<String, Object> result = new HashMap<String, Object>();
		// 超重数据
		HwDataOverrunstationHistory hwDataOverrunstationHistory = hwDataOverrunstationHistoryMapper.selectById(fid);
		String taskId = hwDataOverrunstationHistory.getfId();
		//调度表
		HwCommandTask hwCommandTask=new HwCommandTask();
		hwCommandTask.setfId(taskId);
		HwCommandTask hwCommandTask1 = hwCommandTaskMapper.selectOne(hwCommandTask);
		if (hwCommandTask1!=null){
			//调度督导表
			HwSupervision hwSupervision=new HwSupervision();
			EntityWrapper<HwSupervision> supervision = new EntityWrapper<HwSupervision>();
			supervision.eq("F_FromObjectID",hwCommandTask1.getTaskId());
			List<HwSupervision> hwSupervisions = hwSupervisionMapper.selectList(supervision);
			List<SupervisionVo> supervisionVo =new ArrayList<>();
			for (HwSupervision hwSupervision1 : hwSupervisions) {
				SupervisionVo supervisionVo1= new SupervisionVo();
				supervisionVo1.setfSpvid(hwSupervision1.getfSpvid());
				supervisionVo1.setfFromobjectid(hwSupervision1.getfFromobjectid());
				supervisionVo1.setfFromtype(hwSupervision1.getfFromtype());
				supervisionVo1.setfFromdepcode(hwSupervision1.getfFromdepcode());
				supervisionVo1.setfFromuserid(hwSupervision1.getfFromuserid());
				supervisionVo1.setfFromusername(hwSupervision1.getfFromusername());
				supervisionVo1.setfFromtime(hwSupervision1.getfFromtime());
				supervisionVo1.setfTitle(hwSupervision1.getfTitle());
				supervisionVo1.setfFromsrc(hwSupervision1.getfFromsrc());
				supervisionVo1.setfSpvcontent(hwSupervision1.getfSpvcontent());
				supervisionVo1.setfCurrentstep(hwSupervision1.getfCurrentstep());
				supervisionVo1.setfBacktype(hwSupervision1.getfBacktype());
				supervisionVo1.setfBackdepcode(hwSupervision1.getfBackdepcode());
				supervisionVo1.setfBackdepname(hwSupervision1.getfBackdepname());
				supervisionVo1.setfBackuserid(hwSupervision1.getfBackuserid());
				supervisionVo1.setfBackusername(hwSupervision1.getfBackusername());
				supervisionVo1.setfBackuserphone(hwSupervision1.getfBackuserphone());
				supervisionVo1.setfBacktime(hwSupervision1.getfBacktime());
				supervisionVo1.setfBackfile(hwSupervision1.getfBackfile());
				supervisionVo1.setfBackassignstate(hwSupervision1.getfBackassignstate());
				supervisionVo1.setIsStagestate(hwSupervision1.getIsStagestate());
				//附件表
				EntityWrapper<HwBaseAnnexesfile> annexesFile = new EntityWrapper<HwBaseAnnexesfile>();
				annexesFile.eq("F_FolderId",hwSupervision1.getfBackfile());
				List<HwBaseAnnexesfile> list = hwBaseAnnexesfileMapper.selectList(annexesFile);
				supervisionVo1.setFuJan(list);
				supervisionVo.add(supervisionVo1);

			    }
			// 车辆的图片
			result.put("weighingData",hwDataOverrunstationHistory);
			//调度督导表
			result.put("checkTheSupervision",supervisionVo);
		}else {
			// 车辆的图片
			result.put("weighingData",hwDataOverrunstationHistory);
		}
		return ResponeResultUtil.successNotice(HWSystemCode.SUCCESS, result);

	}
}
